M.remoteStaticPathEnable = false;


formformat = {
    "api": [
        {
            "key": "id",
            "note": "id",
            "value": "1",
            "dateFormat": {
                "dateType": "String"
            }
        },
        {
            "key": "username",
            "note": "用户名",
            "value": "zs",
            "dateFormat": {
                "dateType": "String",
                "required":false
            }
        },

        {
            "key": "phone",
            "note": "手机",
            "value": "15067374384",
            "dateFormat": {
                "dateType": "String",
                 "required":false
            }
        },
        {
            "key": "address",
            "note": "住址",
            "value": "背景",
            "dateFormat": {
                "dateType": "String",
                "required":false
            }
        },
        {
            "key": "sex",
            "note": "性别",
            "detailNote": "false:男  true：女",
            "value": "false",
            "dateFormat": {
                "dateType": "Bool",
                "selectList": [
                    {
                        "value": "true",
                        "name": "是"
                    },
                    {
                        "value": "false",
                        "name": "否"
                    }
                ]
            }
        }
    ]
}

app.get("/getFormformat", (req, res) => {
    res.send(M.result(formformat))
})



app.post("/add", (req, res) => {
    r = M.add(JSON.parse(req.body));
    res.send(M.result(r));
});

app.get("/delete", (req, res) => {
    M.deleteById(req.params.id);
    res.send(M.result("ok"));
});

app.post("/update", (req, res) => {
    r = M.update(JSON.parse(req.body));
    res.send(M.result("ok"));
});

app.get("/getById", (req, res) => {
    r = M.getById(req.params.id);
    res.send(M.result(r));
});

app.get("/listAll", (req, res) => {
    r = M.listAll();
    res.send(M.result(r));
});

app.get("/listByParentId", (req, res) => {
    r = M.listByProp({ parentId: req.params.parentId });
    res.send(M.result(r));
});

app.get("/listByPage", (req, res) => {
    let r;
    if(req.params.name){
        r = M.listByPage(req.params.startPage, req.params.limit,{username:req.params.name});
    }else{
        r = M.listByPage(req.params.startPage, req.params.limit);
    }
    res.send(M.result(r));
})